title="order-detail"
url = '/:slug|orderdetail-\d+.html$'
layout="default-x"

[session]
security = "user"
redirect = "account/login"
==

use Jason\Ccshop\Models\OrderStatus;
use GuzzleHttp\Client;

function onStart() {
header("Content-type: text/html; charset=utf-8");
$userid_login = $this['user']['attributes']['id'];
$slugArr = explode('-', str_replace('.html', '', $this->param('slug')));
$sn = $slugArr['1'];
$this['sn'] = $sn;

$order = App::make('Jason\Ccshop\Controllers\Orders')->orderDetail($sn);
$userid_order = $order['attributes']['uid'];
if($order == null){
return redirect('/account/login.html');
}
if($userid_order != $userid_login){
return redirect('/account/login.html');
}
$this['orderStatusCode'] = $order->order_status->code;

$this['order'] = $order;
}
==
<!-- contents -->
<div id="contents">
  <div class="title-return">
            <h2>ご注文の詳細照会</h2>
            <a href="javascript:;" onclick="history.go(-1);return false;"><img src="{{ 'assets/img/btn_back.gif'|theme}}" alt="戻る"></a>
            <!--发送邮件连接到邮件发送页面-->
            <a  href="/sendorderemail-{{ order.sn }}.html"  class="icon-email">
                <i class="fa fa-envelope"></i>
                <span>contact us</span>
            </a>
        </div>
  <h3 class="title_main">ご注文詳細：</h3>
  <section>
    <table class="company orderDetailCont">
      <tr>
        <th>ご注文番号：</th>
        <td>{{ order.sn }}</td>
      </tr>
      <tr>
        <th>注文時間：</th>
        <td>{{ order.created_at }}</td>
      </tr>
      <tr>
        <th>注文者：</th>
        <td>{{ order.lastname }} {{ order.firstname }}</td>
      </tr>
      <tr>
        <th>メールアドレス：</th>
        <td>{{ order.email }}</td>
      </tr>
      <tr>
        <th>電話番号：</th>
        <td>{{ order.phonenumber }}</td>
      </tr>
      <tr>
        <th>地址：</th>
        <td>{{ order.country.name }}, {{ order.state.name }}, {{ order.city }}, {{ order.address }}</td>
      </tr>
      <tr>
        <th>郵便番号：</th>
        <td>{{ order.postcode }}</td>
      </tr>
      <tr>
        <th>配送方法：</th>
        <td>{{ order.shippingmethod.name }}</td>
      </tr>
      <tr>
        <th>決済方法：</th>
        <td>{{ order.payment.name }}</td>
      </tr>
    </table>
    <h3 class="title_main">ご注文商品リスト</h3>
    <ul class="list_product_line list_product_line_checkbox clearfix mt0">
      {% for m, orderproduct in order.products %}
      {% set condition = { 'id': orderproduct.product_id } %}
      {% set product = catalog.product(condition) %}
      <li class="list_product_item">
        <div class="box_list">
          <div class="list_product_link box_list_main">
            <div class="cart-content">
                    {% for m, orderproduct in order.products %}
                    {% set condition = { 'id': orderproduct.product_id } %}
                    {% set product = catalog.product(condition) %}
                    <div class="order-des" style="border:none;">
                        <div class="description">
                            <p class="prdImg">
                                <a href="{{ product.url }}"><img src="{{ product.getMainThumb(80) }}" alt="{{ orderproduct.name }}"></a>
                            </p>
                            <strong class="prdName"><a href="{{ product.url }}">{{ orderproduct.name }}</a></strong>
                            <!--<ul class="info info-detail">
                                <li>
                                    {%for m,option in orderproduct.options %}
                                    <span>{{m}}:{{option[0]}}</span>
                                    {% endfor %}    
                                </li>
                                <li>
                                    <span><strong>{{ orderproduct.price|formatPriceNotRate }}</strong></span>
                                    <span><strong>× {{ orderproduct.qty }}</strong>個</span><br />
                                    <span><strong>{{ order.total_price|formatPriceNotRate }}</strong></span>
                                </li>
                            </ul>-->
                            <ul class="info info-other">
                                <li>
                                    {%for m,option in orderproduct.options %}
                                    <span>{{m}}:{{option[0]}}</span>
                                    {% endfor %}    
                                </li>
                                <li>
                                    <span class="price"><strong>{{ orderproduct.price|formatPriceNotRate }}</strong></span>
                                    <span><strong>× {{ orderproduct.qty }}</strong>個</span>
                                </li>
                            </ul>
                        </div>
                        <!--<p class="option">
                            {%for m,option in orderproduct.options %}
                            [{{m}}:{{option[0]}}]
                            {% endfor %}
                            {% if order.status_id == 5  %}
                            <a class="btn_pingl fr" href="javascript:;" data-product-id="{{ orderproduct.product_id }}">レビュー</a>
                            {% endif %}
                        </p>-->
                    </div>
                    {% endfor %}
                    {% if order.status_id == 1 or order.status_id == 3 or order.status_id == 9 %}
                    <!--<div class="btnArea">
                        <a href="{{ 'account/orders'|page }}" class="btnBasic" data-request="onCancelOrder"
                           data-request-data="sn: {{ order.sn }}">注文キャンセル</a>
                    </div>-->
                    {% endif %}
                </div>
          </div>
        </div>
      </li>
      {% endfor %}
    </ul>
    <div class="open_file">
      {{ form_open({ request: 'onPushReview', files: true }) }}
      <input type="hidden" name="product" value="{{ product.id }}">
      <input type="hidden" class="input-text required-entry" value="4" id="rating_rank" name="rating">
      <div class="reviewContentsTitle">
        総合評価:
        <span id="score">
            <a name="1" class="reviewStar size4"></a>
            <a name="2" class="reviewStar size4"></a>
            <a name="3" class="reviewStar size4"></a>
            <a name="4" class="reviewStar size4"></a>
            <a name="5" class="reviewStar size4"></a>
        </span>
      </div>
      <div class="submitReview">
        <label class="ipass">ニックネーム<span class="red_color">*</span></label>
        <input type="text" class="commonInput" id="nickname_field" name="name">
        <label class="ipass">レビューのタイトル<span class="red_color">*</span></label>
        <input type="text" class="commonInput" id="summary_field" name="title">
        <label class="ipass">商品レビュー本文<span class="red_color">*</span></label>
        <textarea class="required-entry" rows="3" cols="5" id="review_field" name="content"></textarea>
        <div class="clone_sq">
          <div class="file_style_sq">
            <a href="javascript:void(0)">画像をアップロードする<input class="filea_put" name='images[]' onchange="readFile(this);" type="file" /></a>
            <div class="each_file">
              <input type="text">
              <span></span>                
            </div>
          </div>
        </div>
        <button class="button_decide mt10" title="Submit Review" type="submit">
            <span class="button_txt">レビューを投稿する</span>
        </button>
      </div>
      {{ form_close() }} 
    </div>
    <ul class="list_product_review">
        <table class="companyTable">
          <tr>
            <th>金額</th>
            <td><span class="force_color">{{ order.products_price|formatPriceNotRate }}</span></td>
          </tr>
          <tr>
            <th>配送料金</th>
            <td><span class="force_color">{{ order.freight|formatPriceNotRate }}</span></td>
          </tr>

          <tr>
            <th>割引金額</th>
            <td><span class="force_color">-
                {% for od in order.discount %}
                      {% if od.type == 'points' %}
                      ポイント割引
                      {{ od.price|format }}
                      {% elseif od.type == 'promoAmount' %}
                      {{ od.price|format }}
                      {% elseif od.type == 'coupon' %}
                      クーポン割引
                      {{ od.price|format }}
                      {% endif %}
                {% endfor %}
            </span>
            </td>
          </tr>
          <tr>
            <th style="font-size:18px;">合計金額</th>
            <td style="font-size:18px;"><span class="force_color">{{ order.total_price|formatPriceNotRate }}</span></td>
          </tr>
          <tr style="border:none;position:relative;">
              <td style="width: 100%;">
              {% partial 'account/order-detail-status-operation' order=order %}
              </td>
          </tr>
        </table>
    </ul>
  </section>
</div>
{% partial 'account/order-cancel-pop' %}
<!-- end contents -->
{% put scripts %}
<script type="text/javascript">
$(function() {
  //click reviews
  $(".open_file").hide();
  $(".btn_pingl").click(function(){
      var product_id = $(this).attr('data-product-id');
      $("input[name='product']").val(product_id);
      $(".open_file").slideToggle();
  })
})
// Star rating
var GradList = document.getElementById("score").getElementsByTagName("a");
for(var i=0;i < GradList.length;i++){
    GradList[i].onmouseover = function(){
        for(var Qi=0;Qi<GradList.length;Qi++){
            GradList[Qi].className = 'reviewStar size4';
        }
        for(var Qii=0;Qii<this.name;Qii++){
            GradList[Qii].className = 'reviewStar size4 star1';
        }
        $("#rating_rank").val(Qii);
    }
}

var num_cunt = 0;
    var kaiguan = true;
    var file_html = "<div class='file_style_sq'><div><a href='javascript:void(0)'>画像をアップロードする<input class='filea_put' name='images[]' onchange='readFile(this);' type='file'  /></a></div><div class='each_file'><input type='text'><span></span></div></div>";
   function readFile(self) {
      var file = self.files[0];
      console.log(file.name);
      $(self).parent().parent().parent().find(".each_file input").val(file.name);
      console.log($(self).parent().parent().find(".each_file input"));
      if ($(".each_file").eq(num_cunt).find("input").val() != "" && kaiguan) {
        // Upload a few max
        var file_lenqta = $(".file_style_sq").length;
        console.log(file_lenqta)
        if (file_lenqta >= 3) {
          kaiguan == false;
        } else {
          kaiguan == true;
          $(".clone_sq").append(file_html);
        }
      }
      // if delete upload    
      $(".each_file span").each(function () {
        $(this).click(function () {
          // Upload a few min
          var file_lenqta = $(".file_style_sq").length;
          console.log(file_lenqta)
          if (file_lenqta <= 1) {
            kaiguan == false;
          } else {
            kaiguan == true;
            $(this).parent().parent().remove();
          }
        })
      })

      num_cunt++;
    }
</script>
{% endput %}